/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upn.sigeadmi.cxc.bc;

import edu.upn.sigeadmi.cxc.be.TasaInteres;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Administrador
 */
public class TasaInteresDelegate {

    private TasaInteresFacadeLocal local;

    public TasaInteresDelegate() {
        local = lookupTasaInteresFacade();
    }

    public void eliminar(TasaInteres tasaInteres) throws Exception {
        try {
            local.remove(tasaInteres);
        } catch (Exception e) {
            local=lookupTasaInteresFacade();
            throw e;
        }

    }

    public List<TasaInteres> listar() throws Exception{
        try {
            return local.findAll();
        } catch (Exception e) {
            local=lookupTasaInteresFacade();
            throw e;
        }

    }

    public void editar(TasaInteres tasaInteres) throws Exception{
        try {
            local.edit(tasaInteres);
        } catch (Exception e) {
            local=lookupTasaInteresFacade();
            throw e;
        }

    }

    public void crear(TasaInteres tasaInteres) throws Exception{
        try {
            local.create(tasaInteres);
        } catch (Exception e) {
            local=lookupTasaInteresFacade();
            throw e;
        }

    }

    private TasaInteresFacadeLocal lookupTasaInteresFacade() {
        try {
            Context c = new InitialContext();
            return (TasaInteresFacadeLocal) c.lookup("java:comp/env/TasaInteresFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

}
